local quanqing = fk.CreateSkill{
  name = "steam__qiongkubipu",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["steam__qiongkubipu"] = "穷寇必迫",
  [":steam__qiongkubipu"] = "锁定技，其他角色失去最后手牌时，你摸两张牌，其再次获得手牌后对你造成1点伤害。",
  ["@@steam__qiongkubipu"]="已逃跑",
}

quanqing:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(quanqing.name) then return end
    local x = 0
    local backplayer
    for _, move in ipairs(data) do
      if move.from and move.from:isKongcheng() and move.from~=player then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            x = x + 1
            backplayer=move.from
            break
          end
        end
      end
    end
    if x > 0 then
      event:setCostData(self, { extra_data = backplayer })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local backplayer = event:getCostData(self).extra_data
    player:drawCards(2, quanqing.name)
    room:setPlayerMark(backplayer,"@@steam__qiongkubipu", 1)
  end,
})

quanqing:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_refresh = function(self, event, target, player, data)
    if not player:hasSkill(quanqing.name) then return end
    local x = 0
    local backplayer
    for _, move in ipairs(data) do
      if move.to and  move.to:getMark("@@steam__qiongkubipu") > 0  and move.toArea == Card.PlayerHand then
        for _, info in ipairs(move.moveInfo) do
          
            x = x + 1
            backplayer=move.to
            break
        end
      end
    end
    if x > 0 then
      event:setCostData(self, { extra_data = backplayer })
      return true
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local backplayer = event:getCostData(self).extra_data
    
    room:setPlayerMark(backplayer,"@@steam__qiongkubipu", 0)
    backplayer:chat("三十年河东，三十年河西，莫欺少年穷！")
    room:damage({
      to=player,
      from=backplayer,
      damage=1,
      skillName=quanqing.name,
    })
  end,
})


return quanqing
